{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import networkx as nx\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " <class 'networkx.classes.digraph.DiGraph'>\n",
      "[('A', 'B'), ('A', 'C'), ('A', 'D'), ('B', 'A'), ('B', 'D'), ('C', 'A'), ('D', 'B'), ('D', 'C')] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "# 创建有向图\n",
    "G = nx.DiGraph()   \n",
    "# 设置有向图的边集合\n",
    "edges = [(\"A\", \"B\"), (\"A\", \"C\"), (\"A\", \"D\"), (\"B\", \"A\"), (\"B\", \"D\"), (\"C\", \"A\"), (\"D\", \"B\"), (\"D\", \"C\")]\n",
    "# 在有向图G中添加边集合\n",
    "for edge in edges:\n",
    "    G.add_edge(edge[0], edge[1])\n",
    "print(G,type(G))\n",
    "print(edges,type(edges))    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAb4AAAEuCAYAAADx63eqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Il7ecAAAACXBIWXMAAAsTAAALEwEAmpwYAAA5mUlEQVR4nO3dZ0BTZ+M28CthSgFBERQRURFxIVVq1cctCuKkjrraqrUOrHW3tVqft7bWuuqqe1utdSuKg1GFWosMByqIgAKigggie4Tk/eAD/1pEQZOck+T6fQwZVxRy5dznvs8tUSgUChAREekIqdABiIiI1InFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0REOoXFR0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5NEaf2FeBTKSl+4rc7Qhajh4Ap5YR4K799EZuAWFD28A6t+M164X6GsFBsuxGPTGDc1JiYiTcGhThKdJ7lFCL6TXunwptT4HZg0fR91Bn2JvBtBKE5PfOHnCgVwPjYdGblFqg9LRBqHxUeiczgypUr3M7JtBj1zKxTdj67wMwmAw1eq9jxEpFtYfCQ6t1OzX1iy8Cp6prUgL8ypcHuhTI7bjyreTkTE4iPRyS6UVfm+pTkZkBqbVfI8JcqKRERahMVHomNuXLU5V0WP7qA0JwNGdi0qeZ6q7cpORLqFszpJdJzrmsNIP7XS4U55UT4K79/E08AteKdldxhaO1S4j7G+FM71Xn4kSES6jcVHojO0nR1WBd6pcHv64UX/W8cngUHtBjB/bzBM3+370udQABja1k7FSYlIE7H4SHSsTI3QzakOAmLSypc02PnsqPLjJRKgR7M65ReuJiL6J57jI1Ga2t0Rxvp6b/RYY309+HR3VHIiItIWLD4SpTYNLDDfyxk1DKr3K1rDQIr5Xs68XBkRVYpDnSRaYzo4AAAWn75dpd0ZjPX1MN/LufxxREQvw4tUk+hFpWRhw4V4nI9NhwTPF6eXKduPr0ezOvDp7sgjPSJ6LRYfaYyM3CIcvpKC249ykF1YAnNjAzjXM8PQtnacyEJEVcbiIyIincLJLUREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFNYfEREpFP+P4YctOiHrLxdAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 有向图可视化\n",
    "layout = nx.spring_layout(G)\n",
    "nx.draw(G, pos=layout, with_labels=True)\n",
    "plt.show()#图正确的表达出来了  只是下面这个图显示，每次运行显示都不一样，位置变动（物理信息没有变的情况下 ABCD在屏幕中显示的位置有变）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "简化模型的PR值： {'A': 0.33333396911621094, 'B': 0.22222201029459634, 'C': 0.22222201029459634, 'D': 0.22222201029459634}\n"
     ]
    }
   ],
   "source": [
    "# 计算简化模型的PR值\n",
    "pr = nx.pagerank(G, alpha=1)\n",
    "print(\"简化模型的PR值：\", pr)#这个结果 就是用转移矩阵推导出来的那个结果  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "随机模型的PR值： {'A': 0.3214290507775999, 'B': 0.22619031640746662, 'C': 0.22619031640746662, 'D': 0.22619031640746662}\n"
     ]
    }
   ],
   "source": [
    "# 计算随机模型的PR值\n",
    "pr = nx.pagerank(G, alpha=0.8)\n",
    "print(\"随机模型的PR值：\", pr)#这个结果 就是用转移矩阵推导出来的那个结果"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
